package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.OaKeyworkTaskindexQuery;
import com.jcfk.system.domain.dto.OaKeyworkTaskindexDTO;
import com.jcfk.system.service.OaKeyworkTaskindexService;
import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 重点工作任务指标
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-03-26
 */
@Api(tags = {"重点工作任务指标管理"})
@RestController
@RequestMapping("oakeyworktaskindex")
public class OaKeyworkTaskindexController {
    @Autowired
    private OaKeyworkTaskindexService oaKeyworkTaskindexService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<OaKeyworkTaskindexQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询重点工作任务指标")
    @PostMapping("/queryByPage")
    public RetPage<OaKeyworkTaskindexDTO> queryByPage(@RequestBody ReqPageParam<OaKeyworkTaskindexQuery> requestParam) {
        DataPage<OaKeyworkTaskindexDTO> page = new DataPage<OaKeyworkTaskindexDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            OaKeyworkTaskindexDTO.class);
        page = oaKeyworkTaskindexService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  重点工作任务指标
     * 根据id 查询详情
     */
    @ApiOperation("查询重点工作任务指标")
    @GetMapping("/get/{id}")
    public RetResult<OaKeyworkTaskindexDTO> get(@PathVariable("id") String id) {
            OaKeyworkTaskindexDTO item = oaKeyworkTaskindexService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理重点工作任务指标
     */
    @ApiOperation("保存重点工作任务指标")
    @PostMapping("/save")
    @RequestLogHeader(modular = "重点工作任务指标管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid OaKeyworkTaskindexDTO oaKeyworkTaskindex) {
        // 数据校验
        RetResult ret = oaKeyworkTaskindexService.isValid(oaKeyworkTaskindex);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(oaKeyworkTaskindex.getId())){
            // 新增
            oaKeyworkTaskindexService.insert(oaKeyworkTaskindex);
        } else{
            // 更新
            oaKeyworkTaskindexService.update(oaKeyworkTaskindex);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除重点工作任务指标
     */
    @ApiOperation("批量删除重点工作任务指标")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "重点工作任务指标管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody OaKeyworkTaskindexDTO oaKeyworkTaskindex) {
        return RetResult.ok(oaKeyworkTaskindexService.removeBigBatch(oaKeyworkTaskindex.getIds()));
    }

}
